#include "osObjects.h"  
#include "systimer.h"
#include "rtctime.h"
#include "pincfg.h"
#include "templib.h"
#include "tempctrlib.h"
#include "sys.h"
//---------------------------------------------------------------------------//
uint16_t PulseTimerTest = 0;
/*----------------------------------------------------------------------------
 *      Global Functions
 *---------------------------------------------------------------------------*/
 void SysIoCheck(void);
 void SysIoCtr(void);
/*--------------------------- os_idle_demon ---------------------------------*/

const TEMP_TABLE_Type Pt100_100_Table[]={{-12864,-620},{-3268,-160},{8125,400},{19430,970},{20391,1020},{INT16_MAX,INT16_MAX}};
 
uint32_t uuid[3];
uint32_t memInfo;

uint32_t IdleTaskCnt;

uint16_t ParT[6]={60,240,240,100,3,0};

TEMP_OBJ_Type TempObj;
PID_Type      TempPid;



/// \brief The idle demon is running when no other thread is ready to run
void os_idle_demon (void)
{
    //uint16_t Cnt;
	
	uuid[0] = *((const uint32_t *) 0x1FFFF7AC);
	uuid[1] = *((const uint32_t *) 0x1FFFF7B0);
	uuid[2] = *((const uint32_t *) 0x1FFFF7B4);
	memInfo = *((const uint32_t *) 0x1FFFF7E0);
	SysTickInit();
    
    TempPid.Sv = 250;
    TempPid.Pv = 300;
    PidSet(&TempPid,ParT,1000);
    PidClr(&TempPid);
    
    TempObj.Err   = 0;
    TempObj.ADVal = 4000;
	TempObj.Temp   = 0;
	TempObj.TempDis = 0;
    TempObj.TempReal = 0;
	TempObj.TempTab = Pt100_100_Table;
    TempObj.Mark.MarkADL  =  1000;
	TempObj.Mark.MarkADH  =  8000;
	TempObj.Correct.PB    =  0;
	TempObj.Correct.PK    =  0;
	TempObj.Limite.LimiteL=  800;
	TempObj.Limite.LimiteH=  -200; 
    TempObj.Flt = 0.8;
    
    TimeCur.Year = 2017;
    TimeCur.Mon  = 6;
    TimeCur.Day  = 1;
    TimeCur.Hour = 12;
    TimeCur.Min  = 30;
    TimeCur.Sec  = 30;
    
    for (;;)
	{
		//---------------------------------------------------------------------//
		// HERE: include optional user code to be executed when no thread runs.

		IdleTaskCnt++;
		
        SysPulseClear();
        SysPulseCreat();
        
        PidCal(&TempPid);
        TempCal(&TempObj);
        
        if(bPulse_1s){
            TimeRun();
            Led1() = !Led1();
        }
        
        if(bPulse_250ms){
            Led2() = !Led2();
        }
        
        if(bPulse_125ms){
            if( Led1())
                Led3() = !Led3();
        }
        
        SysIoCheck();
        SysIoCtr();

	}
}


void SysIoCheck(){

}

void SysIoCtr(){

}

